﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	SqlQueryBuilderConditionGroup.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using System.ComponentModel;
using System.Linq;
using Microsoft.SharePoint;

namespace Smart.Common.Entities
{
	/// <summary>
	/// Group of condition items
	/// </summary>
	[Localizable(false)]
	public class SqlQueryBuilderConditionGroup<TExecutorType> : SqlQueryBuilderItemGroup<TExecutorType>, IQueryBuilderConditionGroup<TExecutorType>
		where TExecutorType : class
	{
		/// <summary>
		/// Parent Group
		/// </summary>
		public IQueryBuilderConditionGroup<TExecutorType> Parent
		{
			get { return Group as SqlQueryBuilderConditionGroup<TExecutorType>; }
		}

		public SqlQueryBuilderConditionGroup(string op)
			: base(op)
		{
		}

		#region Universal reflected methods

		public virtual Func<string, SqlQueryBuilderConditionGroup<TExecutorType>> GetMethod(FilterCondition op)
		{
			var mi = GetType().GetMethod(op.ToString(), new[] { typeof(string) });

			if (mi == null)
				return null;

			return
				field => mi.Invoke(this, new object[] { field }) as SqlQueryBuilderConditionGroup<TExecutorType>;
		}

		public virtual Func<string, object, SqlQueryBuilderConditionGroup<TExecutorType>> GetMethod(FilterCondition op, Type vt)
		{
			var mi = GetType().GetMethod(op.ToString(), new[] { typeof(string), vt });

			if (mi == null)
				return null;

			return
				(field, value) => mi.Invoke(this, new[] { field, value }) as SqlQueryBuilderConditionGroup<TExecutorType>;
		}

		public virtual Func<string, object, object, SqlQueryBuilderConditionGroup<TExecutorType>> GetMethod(FilterCondition op, Type vt1, Type vt2)
		{
			var mi = GetType().GetMethod(op.ToString(), new[] { typeof(string), vt1, vt2 });

			if (mi == null)
				return null;

			return
				(field, value1, value2) => mi.Invoke(this, new[] { field, value1, value2 }) as SqlQueryBuilderConditionGroup<TExecutorType>;
		}

		public virtual IQueryBuilderConditionGroup<TExecutorType> Filter(string field, FilterCondition op)
		{
			var method = GetMethod(op);

			if (method == null)
				throw new NotSupportedException();

			return method(field);
		}

		public virtual IQueryBuilderConditionGroup<TExecutorType> Filter(string field, FilterCondition op, object value)
		{
			var method = GetMethod(op, (value == null ? typeof(string) : value.GetType()));

			if (method == null)
				throw new NotSupportedException();

			return method(field, value);
		}

		public virtual IQueryBuilderConditionGroup<TExecutorType> Filter(string field, FilterCondition op, object value1, object value2)
		{
			var method = GetMethod(op, (value1 == null ? typeof(string) : value1.GetType()), (value2 == null ? typeof(string) : value2.GetType()));

			if (method == null)
				throw new NotSupportedException();

			return method(field, value1, value2);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Filter(Guid fieldId, FilterCondition op)
		{
			throw new NotSupportedException("Filter not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Filter(Guid fieldId, FilterCondition op, object value)
		{
			throw new NotSupportedException("Filter not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Filter(Guid fieldId, FilterCondition op, object value1, object value2)
		{
			throw new NotSupportedException("Filter not supported by Sql data source");
		}

		#endregion

		#region Generics

		/// <summary>
		/// Adds generic condition
		/// </summary>
		public SqlQueryBuilderConditionGroup<TExecutorType> Condition(string field, string op, object value)
		{
			AddItem(new SqlQueryBuilderConditionItem<TExecutorType>(field, op, value));

			return this;
		}

		/// <summary>
		/// Adds generic condition
		/// </summary>
		public SqlQueryBuilderConditionGroup<TExecutorType> Condition(string field, string op, int value)
		{
			AddItem(new SqlQueryBuilderConditionItem<TExecutorType>(field, op, value));

			return this;
		}

		/// <summary>
		/// Adds generic condition
		/// </summary>
		public SqlQueryBuilderConditionGroup<TExecutorType> Condition(string field, string op, double value)
		{
			AddItem(new SqlQueryBuilderConditionItem<TExecutorType>(field, op, value));

			return this;
		}

		/// <summary>
		/// Adds generic condition
		/// </summary>
		public SqlQueryBuilderConditionGroup<TExecutorType> Condition(string field, string op, bool value)
		{
			AddItem(new SqlQueryBuilderConditionItem<TExecutorType>(field, op, value));

			return this;
		}

		/// <summary>
		/// Adds generic condition
		/// </summary>
		public SqlQueryBuilderConditionGroup<TExecutorType> Condition(string field, string op, DateTime value)
		{
			AddItem(new SqlQueryBuilderConditionItem<TExecutorType>(field, op, value));

			return this;
		}

		/// <summary>
		/// Adds generic condition
		/// </summary>
		public SqlQueryBuilderConditionGroup<TExecutorType> Condition(string field, string op, string value)
		{
			AddItem(new SqlQueryBuilderConditionItem<TExecutorType>(field, op, value));

			return this;
		}

		/// <summary>
		/// Adds generic statement
		/// </summary>
		public SqlQueryBuilderConditionGroup<TExecutorType> Statement(string field, string op, string statement)
		{
			AddItem(new SqlQueryBuilderStatementItem<TExecutorType>(field, string.Empty, op, statement));

			return this;
		}

		#endregion

		#region Eq

		public IQueryBuilderConditionGroup<TExecutorType> Eq(string field, string value)
		{
			return Condition(field, "=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Eq(string field, int value)
		{
			return Condition(field, "=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Eq(string field, double value)
		{
			return Condition(field, "=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Eq(string field, bool value)
		{
			return Condition(field, "=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Eq(string field, DateTime value)
		{
			return Condition(field, "=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Eq(Guid fieldId, string value)
		{
			throw new NotSupportedException("Eq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Eq(Guid fieldId, int value)
		{
			throw new NotSupportedException("Eq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Eq(Guid fieldId, double value)
		{
			throw new NotSupportedException("Eq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Eq(Guid fieldId, bool value)
		{
			throw new NotSupportedException("Eq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Eq(Guid fieldId, DateTime value)
		{
			throw new NotSupportedException("Eq not supported by Sql data source");
		}

		#endregion

		#region Neq

		public IQueryBuilderConditionGroup<TExecutorType> Neq(string field, string value)
		{
			return Condition(field, "<>", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Neq(string field, int value)
		{
			return Condition(field, "<>", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Neq(string field, double value)
		{
			return Condition(field, "<>", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Neq(string field, bool value)
		{
			return Condition(field, "<>", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Neq(string field, DateTime value)
		{
			return Condition(field, "<>", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Neq(Guid fieldId, string value)
		{
			throw new NotSupportedException("Neq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Neq(Guid fieldId, int value)
		{
			throw new NotSupportedException("Neq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Neq(Guid fieldId, double value)
		{
			throw new NotSupportedException("Neq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Neq(Guid fieldId, bool value)
		{
			throw new NotSupportedException("Neq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Neq(Guid fieldId, DateTime value)
		{
			throw new NotSupportedException("Neq not supported by Sql data source");
		}

		#endregion

		#region Geq

		public IQueryBuilderConditionGroup<TExecutorType> Geq(string field, string value)
		{
			return Condition(field, ">=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Geq(string field, int value)
		{
			return Condition(field, ">=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Geq(string field, double value)
		{
			return Condition(field, ">=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Geq(string field, bool value)
		{
			return Condition(field, ">=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Geq(string field, DateTime value)
		{
			return Condition(field, ">=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Geq(Guid fieldId, string value)
		{
			throw new NotSupportedException("Geq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Geq(Guid fieldId, int value)
		{
			throw new NotSupportedException("Geq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Geq(Guid fieldId, double value)
		{
			throw new NotSupportedException("Geq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Geq(Guid fieldId, bool value)
		{
			throw new NotSupportedException("Geq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Geq(Guid fieldId, DateTime value)
		{
			throw new NotSupportedException("Geq not supported by Sql data source");
		}

		#endregion

		#region Leq

		public IQueryBuilderConditionGroup<TExecutorType> Leq(string field, string value)
		{
			return Condition(field, "<=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Leq(string field, int value)
		{
			return Condition(field, "<=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Leq(string field, double value)
		{
			return Condition(field, "<=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Leq(string field, bool value)
		{
			return Condition(field, "<=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Leq(string field, DateTime value)
		{
			return Condition(field, "<=", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Leq(Guid fieldId, string value)
		{
			throw new NotSupportedException("Leq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Leq(Guid fieldId, int value)
		{
			throw new NotSupportedException("Leq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Leq(Guid fieldId, double value)
		{
			throw new NotSupportedException("Leq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Leq(Guid fieldId, bool value)
		{
			throw new NotSupportedException("Leq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Leq(Guid fieldId, DateTime value)
		{
			throw new NotSupportedException("Leq not supported by Sql data source");
		}

		#endregion

		#region GT

		public IQueryBuilderConditionGroup<TExecutorType> Gt(string field, string value)
		{
			return Condition(field, ">", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Gt(string field, int value)
		{
			return Condition(field, ">", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Gt(string field, double value)
		{
			return Condition(field, ">", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Gt(string field, bool value)
		{
			return Condition(field, ">", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Gt(string field, DateTime value)
		{
			return Condition(field, ">", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Gt(Guid fieldId, string value)
		{
			throw new NotSupportedException("Gt not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Gt(Guid fieldId, int value)
		{
			throw new NotSupportedException("Gt not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Gt(Guid fieldId, double value)
		{
			throw new NotSupportedException("Gt not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Gt(Guid fieldId, bool value)
		{
			throw new NotSupportedException("Gt not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Gt(Guid fieldId, DateTime value)
		{
			throw new NotSupportedException("Gt not supported by Sql data source");
		}

		#endregion

		#region LT

		public IQueryBuilderConditionGroup<TExecutorType> Lt(string field, string value)
		{
			return Condition(field, "<", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Lt(string field, int value)
		{
			return Condition(field, "<", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Lt(string field, double value)
		{
			return Condition(field, "<", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Lt(string field, bool value)
		{
			return Condition(field, "<", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Lt(string field, DateTime value)
		{
			return Condition(field, "<", value);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Lt(Guid fieldId, string value)
		{
			throw new NotSupportedException("Lt not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Lt(Guid fieldId, int value)
		{
			throw new NotSupportedException("Lt not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Lt(Guid fieldId, double value)
		{
			throw new NotSupportedException("Lt not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Lt(Guid fieldId, bool value)
		{
			throw new NotSupportedException("Lt not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Lt(Guid fieldId, DateTime value)
		{
			throw new NotSupportedException("Lt not supported by Sql data source");
		}

		#endregion

		#region In

		public IQueryBuilderConditionGroup<TExecutorType> In(string field, params int[] values)
		{
			AddItem(new SqlQueryBuilderInItem<TExecutorType>(field, values.Select(value => value.IncapsulateSql()).ToArray()));

			return this;
		}

		public IQueryBuilderConditionGroup<TExecutorType> In(string field, params double[] values)
		{
			AddItem(new SqlQueryBuilderInItem<TExecutorType>(field, values.Select(value => value.IncapsulateSql()).ToArray()));

			return this;
		}

		public IQueryBuilderConditionGroup<TExecutorType> In(string field, params bool[] values)
		{
			AddItem(new SqlQueryBuilderInItem<TExecutorType>(field, values.Select(value => value.IncapsulateSql()).ToArray()));

			return this;
		}

		public IQueryBuilderConditionGroup<TExecutorType> In(string field, params string[] values)
		{
			AddItem(new SqlQueryBuilderInItem<TExecutorType>(field, values.Select(value => value.IncapsulateSql()).ToArray()));

			return this;
		}

		public IQueryBuilderConditionGroup<TExecutorType> In(string field, params DateTime[] values)
		{
			AddItem(new SqlQueryBuilderInItem<TExecutorType>(field, values.Select(value => value.IncapsulateSql()).ToArray()));

			return this;
		}

		public IQueryBuilderConditionGroup<TExecutorType> In(Guid fieldId, params int[] values)
		{
			throw new NotSupportedException("In not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> In(Guid fieldId, params double[] values)
		{
			throw new NotSupportedException("In not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> In(Guid fieldId, params bool[] values)
		{
			throw new NotSupportedException("In not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> In(Guid fieldId, params string[] values)
		{
			throw new NotSupportedException("In not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> In(Guid fieldId, params DateTime[] values)
		{
			throw new NotSupportedException("In not supported by Sql data source");
		}

		#endregion

		#region Additional text conditions

		public IQueryBuilderConditionGroup<TExecutorType> BeginsWith(string field, string value)
		{
			AddItem(new SqlQueryBuilderBeginsWithItem<TExecutorType>(field, "Text", value));

			return this;
		}

		public IQueryBuilderConditionGroup<TExecutorType> Contains(string field, string value)
		{
			AddItem(new SqlQueryBuilderContainsItem<TExecutorType>(field, "Text", value));

			return this;
		}

		public IQueryBuilderConditionGroup<TExecutorType> BeginsWith(Guid fieldId, string value)
		{
			throw new NotSupportedException("BeginsWith not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Contains(Guid fieldId, string value)
		{
			throw new NotSupportedException("Contains not supported by Sql data source");
		}

		#endregion

		#region Additional field conditions

		public IQueryBuilderConditionGroup<TExecutorType> IsNull(string field)
		{
			return Statement(field, "IS NULL", string.Empty);
		}

		public IQueryBuilderConditionGroup<TExecutorType> IsNotNull(string field)
		{
			return Statement(field, "IS NOT NULL", string.Empty);
		}

		public IQueryBuilderConditionGroup<TExecutorType> Membership(string field, MembershipType membership)
		{
			throw new NotSupportedException("Membership not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> IsNull(Guid fieldId)
		{
			throw new NotSupportedException("IsNull not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> IsNotNull(Guid fieldId)
		{
			throw new NotSupportedException("IsNotNull not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Membership(Guid fieldId, MembershipType membership)
		{
			throw new NotSupportedException("Membership not supported by Sql data source");
		}

		#endregion

		#region Additional Lookup conditions

		public IQueryBuilderConditionGroup<TExecutorType> EqL(string field, int value)
		{
			AddItem(new SqlQueryBuilderStatementItem<TExecutorType>(field, " LookupId=\"TRUE\"", "Eq", "<Value Type=\"Lookup\">" + value.ToString() + "</Value>"));

			return this;
		}

		public IQueryBuilderConditionGroup<TExecutorType> NeqL(string field, int value)
		{
			AddItem(new SqlQueryBuilderStatementItem<TExecutorType>(field, " LookupId=\"TRUE\"", "Neq", "<Value Type=\"Lookup\">" + value.ToString() + "</Value>"));

			return this;
		}

		public IQueryBuilderConditionGroup<TExecutorType> Includes(string field, int value)
		{
			throw new NotSupportedException("Includes not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NotIncludes(string field, int value)
		{
			throw new NotSupportedException("NotIncludes not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Includes(string field, string value)
		{
			throw new NotSupportedException("Includes not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NotIncludes(string field, string value)
		{
			throw new NotSupportedException("NotIncludes not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> EqU(string field, SPUser value)
		{
			throw new NotSupportedException("EqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> EqU(string field, int userId)
		{
			throw new NotSupportedException("EqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NeqU(string field, SPUser value)
		{
			throw new NotSupportedException("NeqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NeqU(string field, int userId)
		{
			throw new NotSupportedException("NeqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> IncludesU(string field, SPUser value)
		{
			throw new NotSupportedException("IncludesU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> IncludesU(string field, int userId)
		{
			throw new NotSupportedException("IncludesU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NotIncludesU(string field, SPUser value)
		{
			throw new NotSupportedException("NotIncludesU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NotIncludesU(string field, int userId)
		{
			throw new NotSupportedException("NotIncludesU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> EqU(string field)
		{
			throw new NotSupportedException("EqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NeqU(string field)
		{
			throw new NotSupportedException("NeqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> IncludesU(string field)
		{
			throw new NotSupportedException("IncludesU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NotIncludesU(string field)
		{
			throw new NotSupportedException("NotIncludesU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> EqL(Guid fieldId, int value)
		{
			throw new NotSupportedException("EqL not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NeqL(Guid fieldId, int value)
		{
			throw new NotSupportedException("NeqL not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Includes(Guid fieldId, int value)
		{
			throw new NotSupportedException("Includes not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NotIncludes(Guid fieldId, int value)
		{
			throw new NotSupportedException("NotIncludes not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Includes(Guid fieldId, string value)
		{
			throw new NotSupportedException("Includes not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NotIncludes(Guid fieldId, string value)
		{
			throw new NotSupportedException("NotIncludes not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> EqU(Guid fieldId, SPUser value)
		{
			throw new NotSupportedException("EqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> EqU(Guid fieldId, int userId)
		{
			throw new NotSupportedException("EqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NeqU(Guid fieldId, SPUser value)
		{
			throw new NotSupportedException("NeqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NeqU(Guid fieldId, int userId)
		{
			throw new NotSupportedException("NeqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> IncludesU(Guid fieldId, SPUser value)
		{
			throw new NotSupportedException("IncludesU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> IncludesU(Guid fieldId, int userId)
		{
			throw new NotSupportedException("IncludesU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NotIncludesU(Guid fieldId, SPUser value)
		{
			throw new NotSupportedException("NotIncludesU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NotIncludesU(Guid fieldId, int userId)
		{
			throw new NotSupportedException("NotIncludesU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> EqU(Guid fieldId)
		{
			throw new NotSupportedException("EqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NeqU(Guid fieldId)
		{
			throw new NotSupportedException("NeqU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> IncludesU(Guid fieldId)
		{
			throw new NotSupportedException("IncludesU not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> NotIncludesU(Guid fieldId)
		{
			throw new NotSupportedException("NotIncludesU not supported by Sql data source");
		}

		#endregion

		#region Additional DateTime conditions

		public IQueryBuilderConditionGroup<TExecutorType> DateRangesOverlap(string fieldStartDate, string fieldEndDate, string fieldRecurrenceId, DateTime value, bool includeTimeValue)
		{
			throw new NotSupportedException("DateRangesOverlap not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> DateRangesOverlap(string fieldStartDate, string fieldEndDate, string fieldRecurrenceId, DateRangesOverlapValue value)
		{
			throw new NotSupportedException("DateRangesOverlap not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Eq(string field, DateTime value, bool includeTimeValue)
		{
			return Statement(field, "=", value.IncapsulateSql(includeTimeValue));
		}

		public IQueryBuilderConditionGroup<TExecutorType> Neq(string field, DateTime value, bool includeTimeValue)
		{
			return Statement(field, "<>", value.IncapsulateSql(includeTimeValue));
		}

		public IQueryBuilderConditionGroup<TExecutorType> Geq(string field, DateTime value, bool includeTimeValue)
		{
			return Statement(field, ">=", value.IncapsulateSql(includeTimeValue));
		}

		public IQueryBuilderConditionGroup<TExecutorType> Leq(string field, DateTime value, bool includeTimeValue)
		{
			return Statement(field, "<=", value.IncapsulateSql(includeTimeValue));
		}

		public IQueryBuilderConditionGroup<TExecutorType> Gt(string field, DateTime value, bool includeTimeValue)
		{
			return Statement(field, ">", value.IncapsulateSql(includeTimeValue));
		}

		public IQueryBuilderConditionGroup<TExecutorType> Lt(string field, DateTime value, bool includeTimeValue)
		{
			return Statement(field, "<", value.IncapsulateSql(includeTimeValue));
		}

		public IQueryBuilderConditionGroup<TExecutorType> DateRangesOverlap(Guid fieldIdStartDate, Guid fieldIdEndDate, Guid fieldIdRecurrenceId, DateTime value, bool includeTimeValue)
		{
			throw new NotSupportedException("DateRangesOverlap not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> DateRangesOverlap(Guid fieldIdStartDate, Guid fieldIdEndDate, Guid fieldIdRecurrenceId, DateRangesOverlapValue value)
		{
			throw new NotSupportedException("DateRangesOverlap not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Eq(Guid fieldId, DateTime value, bool includeTimeValue)
		{
			throw new NotSupportedException("Eq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Neq(Guid fieldId, DateTime value, bool includeTimeValue)
		{
			throw new NotSupportedException("Neq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Geq(Guid fieldId, DateTime value, bool includeTimeValue)
		{
			throw new NotSupportedException("Geq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Leq(Guid fieldId, DateTime value, bool includeTimeValue)
		{
			throw new NotSupportedException("Leq not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Gt(Guid fieldId, DateTime value, bool includeTimeValue)
		{
			throw new NotSupportedException("Gt not supported by Sql data source");
		}

		public IQueryBuilderConditionGroup<TExecutorType> Lt(Guid fieldId, DateTime value, bool includeTimeValue)
		{
			throw new NotSupportedException("Lt not supported by Sql data source");
		}

		#endregion

		#region Group conditions

		/// <summary>
		/// Create group
		/// </summary>
		public override SqlQueryBuilderItemGroup<TExecutorType> Create()
		{
			return new SqlQueryBuilderConditionGroup<TExecutorType>(Op) { Group = this, Query = Query };
		}

		//public IQueryBuilderConditionGroup<TExecutorType> And(IEnumerable<SqlQueryBuilderItem<TExecutorType>> items)
		//{
		//    var and = new SqlQueryBuilderAnd<TExecutorType>();
		//    AddItem(and);
		//    and.AddItems(items);
		//    return this;
		//}

		//public IQueryBuilderConditionGroup<TExecutorType> Or(IEnumerable<SqlQueryBuilderItem<TExecutorType>> items)
		//{
		//    var or = new SqlQueryBuilderOr<TExecutorType>();
		//    AddItem(or);
		//    or.AddItems(items);
		//    return this;
		//}

		public IQueryBuilderConditionGroup<TExecutorType> And
		{
			get
			{
				var and = new SqlQueryBuilderAnd<TExecutorType>();

				AddItem(and);

				return and;
			}
		}

		public IQueryBuilderConditionGroup<TExecutorType> Or
		{
			get
			{
				var or = new SqlQueryBuilderOr<TExecutorType>();

				AddItem(or);

				return or;
			}
		}

		public IQueryBuilderConditionGroup<TExecutorType> End
		{
			get { return Parent; }
		}

		public bool IsDateRangesOverlapUsed
		{
			get { return false; }
		}

		#endregion
	}
}